package com.dfrz.problem.service.impl;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.dfrz.problem.dao.EmployeeDao;
import com.dfrz.problem.model.Employee;
import com.dfrz.problem.model.Role;
import com.dfrz.problem.service.GiveroleEmployeeService;
import com.dfrz.problem.utils.IConstant;
import com.dfrz.problem.utils.Result;

public class GiveroleEmployeeServiceImpl implements GiveroleEmployeeService{
	private static final Logger logger = LoggerFactory.getLogger(GiveroleEmployeeServiceImpl.class);

	private EmployeeDao employeeDao;
	
	public void setEmployeeDao(EmployeeDao employeeDao) {
		this.employeeDao = employeeDao;
	}

	@Override
	public Result<Employee> giveroleEmployee(String email,Role role) {
		boolean giveroleSuccess = employeeDao.giveroleEmployee(email, role);
		Result<Employee> result = new Result<Employee>();
		
		if (giveroleSuccess) {
			logger.debug("账户{}赋予角色成功！",email);
			result.setCode(IConstant.DELETE_EMPLOYEE_SUCCESS);
		}
		else {
			logger.debug("账户{}赋予角色失败！",email);
			result.setCode(IConstant.DELETE_EMPLOYEE_ERROR);
		}
		
		//result.setResult(employee);
		return result;
	}

	@Override
	public boolean giveroleEmployee(Employee employee) {
		return employeeDao.updateEmployee(employee);
	}

}
